#include <iostream>

using namespace std;

/*
Do combination for the string.
Assume the string does not contain duplicate character.
for example:
Input: abcd
Output: a		b		c		d
        ab		bc		cd
		ac		bd		
		ad		bcd				
		abc		
		abd		
		acd				
		abcd	
*/

void Combination( char *str, char* out, int len, int cur, int start)
{
	for( int i=start; i<len; i++)
	{
		out[cur]=str[i];
		out[cur+1] = '\0';
		printf("%s\n", out);
		if( i!=len-1)
		{
			//
			// have not reach the last character of str
			//
			Combination(str, out, len, cur+1, i+1);
		}
	}
}

int main()
{
	char * str = "abcd";
	int len = strlen(str);
	char* out = (char*)malloc((len+1)*sizeof(char));

	Combination( str, out, len, 0, 0);
	free(out);

	cout<<"Press any key to terminate..."<<endl;
	return getchar();
}